#ifndef __FLASH_H
#define __FLASH_H
#include <stdint-gcc.h>
#include "common_inc.h"
//////////////////////////////////////////////////////////////////////////////////
//������ֻ��ѧϰʹ�ã�δ��������ɣ��������������κ���;
//ALIENTEKս��STM32������
//W25Q64 ����	   
//����ԭ��@ALIENTEK
//������̳:www.openedv.com
//�޸�����:2012/9/9
//�汾��V1.0
//��Ȩ���У�����ؾ���
//Copyright(C) ������������ӿƼ����޹�˾ 2009-2019
//All rights reserved									  
//////////////////////////////////////////////////////////////////////////////////

//W25Xϵ��/Qϵ��оƬ�б�	   
//W25Q80  ID  0XEF13
//W25Q16  ID  0XEF14
//W25Q32  ID  0XEF15
//W25Q64  ID  0XEF16	
//W25Q128 ID  0XEF17	
#define W25Q80 	0XEF13 	
#define W25Q16 	0XEF14
#define W25Q32 	0XEF15
#define W25Q64 	0XEF16
#define W25Q128	0XEF17

extern uint16_t W25QXX_TYPE;					//����W25QXXоƬ�ͺ�
#define W25QXX_PAGE_SUM 128
#define W25QXX_PAGE_SIZE (4096)
#define W25QXX_SIZE (W25QXX_PAGE_SUM*4096)
//λ������
//�Ĵ����߽���ʼ��ַ 0x42000000
//�Ĵ���λ������ = 0x42000000 + (�Ĵ����ĵ�ַ-0x40000000)*32 + ���ű��*4
#define PAin(n)  *(volatile uint32_t *)(0x42000000+(((uint32_t)&GPIOA->IDR - 0x40000000)<<5) + (n<<2))
#define PEin(n)  *(volatile uint32_t *)(0x42000000+(((uint32_t)&GPIOE->IDR - 0x40000000)<<5) + (n<<2))
#define PAout(n) *(volatile uint32_t *)(0x42000000+(((uint32_t)&GPIOA->ODR - 0x40000000)<<5) + (n<<2))
#define PFout(n) *(volatile uint32_t *)(0x42000000+(((uint32_t)&GPIOF->ODR - 0x40000000)<<5) + (n<<2))
#define PEout(n) *(volatile uint32_t *)(0x42000000+((uint32_t)&GPIOE->ODR - 0x40000000)*32+n*4)

//#define	W25QXX_CS 		PAout(6)  		//W25QXX��Ƭѡ�ź�
#define W25QXX_CS_LOW()     HAL_GPIO_WritePin(W25QXX_CSS_GPIO, W25QXX_CSS_PIN,GPIO_PIN_RESET)
#define W25QXX_CS_HIGH()    HAL_GPIO_WritePin(W25QXX_CSS_GPIO, W25QXX_CSS_PIN,GPIO_PIN_SET)

				 
////////////////////////////////////////////////////////////////////////////
 
//ָ���
#define W25X_WriteEnable		0x06 
#define W25X_WriteDisable		0x04 
#define W25X_ReadStatusReg		0x05 
#define W25X_WriteStatusReg		0x01 
#define W25X_ReadData			0x03 
#define W25X_FastReadData		0x0B 
#define W25X_FastReadDual		0x3B 
#define W25X_PageProgram		0x02 
#define W25X_BlockErase			0xD8 
#define W25X_SectorErase		0x20 
#define W25X_ChipErase			0xC7 
#define W25X_PowerDown			0xB9 
#define W25X_ReleasePowerDown	0xAB 
#define W25X_DeviceID			0xAB 
#define W25X_ManufactDeviceID	0x90 
#define W25X_JedecDeviceID		0x9F

#ifdef __cplusplus
extern "C" {
#endif

void W25QXX_Init(void);
uint16_t W25QXX_ReadID(void);  	    		//��ȡFLASH ID
uint8_t W25QXX_ReadSR(void);        		//��ȡ״̬�Ĵ���
void W25QXX_Write_SR(uint8_t sr);  			//д״̬�Ĵ���
void W25QXX_Write_Enable(void);  		//дʹ�� 
void W25QXX_Write_Disable(void);		//д����
void W25QXX_Write_NoCheck(uint8_t* pBuffer,uint32_t WriteAddr,uint16_t NumByteToWrite);
void W25QXX_Read(uint8_t* pBuffer,uint32_t ReadAddr,uint16_t NumByteToRead);   //��ȡflash
void W25QXX_Write(uint8_t* pBuffer,uint32_t WriteAddr,uint16_t NumByteToWrite);//д��flash
void W25QXX_Erase_Chip(void);    	  	//��Ƭ����
void W25QXX_Erase_Sector(uint32_t Dst_Addr);	//��������
void W25QXX_Wait_Busy(void);           	//�ȴ�����
void W25QXX_PowerDown(void);        	//�������ģʽ
void W25QXX_WAKEUP(void);				//����

void W25QXX_Read_DMA(uint8_t* pBuffer,uint32_t ReadAddr,uint16_t NumByteToRead);


#ifdef __cplusplus
}
/*---------------------------- C++ Scope ---------------------------*/

#endif
#endif
















